<?php include (dirname(__FILE__)."/../include/header.php"); ?>
<?php if(!isset($_SESSION['_shop'])){header("location:../user_login.php");}?>
<?php 
$method="insert";
if($_REQUEST['method']=='detail'){
		$sql="select * from zy_category where cat_id=".$_REQUEST['id']."";
		$result=mysql_query($sql);
		$result=mysql_fetch_array($result);
		$method="update";
}
if($_REQUEST['method']=='update'){
		$sql="update zy_category set cat_name='".$_REQUEST['cat_name']."',sort='".$_REQUEST['sort']."'where cat_id=".$_REQUEST['cat_id'];
		mysql_query($sql);
		header("location:food_cat.php?method=detail&id=".$_REQUEST['cat_id']);
}
if($_REQUEST['method']==''){
		$method="toinsert";
}
if($_REQUEST['method']=='insert'){
		$shop_id = $_SESSION['_shop']['shop_id'];
		$cat_name=$_REQUEST['cat_name'];
		if($cat_name!=""){
		$sql="insert into zy_category(cat_name,shop_id,remark,is_delete,create_user,create_time,update_user,update_time) values('$cat_name','$shop_id','qq',0,'ww',now(),'ww',now())";
		mysql_query($sql);
		header("location:food_cat.php?method=toinsert");
		}else{
			$error="食物类型不能为空";
		}
}
if($_REQUEST['method']=='delete')
{
	$cat_id = $_REQUEST['id'];
	$sql="delete from zy_category where cat_id=".$cat_id;
	mysql_query($sql);
	header("location:food_cat.php");
}
?>
  <div class="container">
    <ul class="breadcrumb">
      <li> 店铺名称 <span class="divider">/</span> </li>
      <li><a href="<?php echo SITE_ROOT;?>/shop/edit_password.php"">修改密码</a></li>
    </ul>
    <div class="row">
      <div class="span12 wash-paper user-center profile">
        <div class="row">
          <div class="span3">
             <?php include (dirname(__FILE__)."/../include/shop/left.php"); ?>
            <div class="span9">
            <div class="main-content">
            <?php if($method=="insert"||$method=="update"){?>
            <div class="content-header">
                <h3>添加/修改食品分类</h3>
              </div>
              <div class="content-inner changepwd">
              
                <form class="form-horizontal" method="post" id="changepwd_form" action="food_cat.php?method=<?php echo $method;?>">
				<div class="field_line" ><font color="red"><?php echo $error;?></font></div>
                  <fieldset>
                    <div class="control-group clear-fix">
                      <label class="control-label" for=""><span class="required">*</span>食品类型：</label>

                      <div class="controls">
                        <input name="cat_name" type="text" id="cat_name" value="<?php echo $result['cat_name'];?>"/>
                        <input type="hidden" name="cat_id" value="<?php echo $result['cat_id'];?>" />
                        <p class="help-block"></p>
                      </div>
					  <div class="control-group clear-fix">
                      <label class="control-label" for=""><span class="required">*</span>食品排序：</label>

                      <div class="controls">
                        <input name="sort" type="text" id="sort" value="<?php echo $result['sort'];?>"/>
                        <input type="hidden" name="cat_id" value="<?php echo $result['cat_id'];?>" />
                        <p class="help-block"></p>
                      </div>
                      <!--end input--> 
                    <div class="form-actions">
                      <input type="submit" class="btn btn-yellow" id="sf_guard_user_changepwd_submit" name="Submit" value="提交" />
                    </div>
                  </fieldset>
                </form>
              </div>
              <?php } ?>
            <!--end marin-content--> 
              <div class="content-header">
                <h3>食品分类管理</h3>
              </div>
              <div class="content-inner">
                <table class="favor_table table table-striped">
                  <thead>
                    <tr>
                      <th>分类名称</th>
					  <th>分类排序</th>
                      <th>修改</th>
                      <th width="60">删除</th>
                    </tr>
                  </thead>
                  <tbody>
                   <?php
				  	$sql=mysql_query("SELECT zy_category.* FROM zy_category where shop_id=".$_SESSION['_shop']['shop_id']." order by sort");
					while($food=mysql_fetch_array($sql)){
				  ?>
                    <tr class="favor_food" >
                      <td><?php echo $food['cat_name'];?></td>
					  <td><?php echo $food['sort'];?></td>
                      <td><span class="admin_del" foodId="1484648"> <a href="food_cat.php?method=detail&id=<?php echo $food['cat_id'];?>">修改</a> </span></td>
                      <td><span class="admin_del" foodId="1484648"> <a href="food_cat.php?method=delete&id=<?php echo $food['cat_id'];?>">删除</a> </span></td>
                    </tr>
                    <?php }?>
                  </tbody>
                </table>
              </div>
              <!--end contentarea--> 
          </div>
        </div>
      </div>
    </div>
  </div>
  <a id="back-to-top" href="javascript:void(0);">
  <div class="backtotop"></div>
  </a> </div>
<?php include (dirname(__FILE__)."/../include/footer.php"); ?>
